﻿using ConfExpert.Datasets;
using ConfExpert.Utility;
using DevTeam;

using System;
using System.Windows.Forms;

namespace ConfExpert.Forms.Satinalma
{
    public partial class OncekiAlimlar : XPopupForm
    {
        int ProductId;
        public OncekiAlimlar(int _ProductId)
        {
            InitializeComponent();
            ProductId = _ProductId;
            this.Text = "Önceki Alımlar: " + ((MyData.V_KumasRow)AppSession.Lookups.V_Kumas.FindByProductId(ProductId)).Name;
        }

        BindingSource bs;
        public int VendorId;
        public int CurrencyId;
        public decimal UnitPrice;
        private void OncekiAlimlar_Load(object sender, EventArgs e)
        {

            bs = gridView1.Init("GetOncekiAlimlar", ProductId);

            gridView1.MakeColumnInvisible("ProductId", "Scan");
            gridView1.Columns["OrderDate"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            gridView1.Columns["OrderDate"].DisplayFormat.FormatString = "d"; //G

            gridView1.MakeReadOnly();
            gridView1.BestFitColumns();

            btnCopy.ItemClick += btnCopy_ItemClick;
            gridView1.DoubleClick += gridView1_DoubleClick;
        }

        void gridView1_DoubleClick(object sender, EventArgs e)
        {
            VendorId = intParse(bs, "VendorId");
            UnitPrice = decimalParse(bs, "UnitPrice");
            CurrencyId = intParse(bs, "CurrencyId");
            this.DialogResult = DialogResult.OK;
        }

        void btnCopy_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            VendorId = intParse(bs, "VendorId");
            UnitPrice = decimalParse(bs, "UnitPrice");
            CurrencyId = intParse(bs, "CurrencyId");
            this.DialogResult = DialogResult.OK;
        }
    }
}